import 'package:FlutterStudy/demo/LikeAnimalIcon1.dart';
import 'package:flutter/material.dart';

import 'LikeAnimalIconImplicit.dart';

class LikeView extends StatefulWidget {
  Widget child;

  LikeView({required this.child});

  @override
  _LikeViewState createState() {
    return _LikeViewState();
  }
}

class _LikeViewState extends State<LikeView>  with TickerProviderStateMixin{
  List<Widget> _likeIcon = [];
  List<Widget> _cackeIcon = [];
  Offset globalOffset = const Offset(0, 0);


  @override
  void initState() {
    super.initState();


  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onDoubleTap: _like,
      /*  onTapDown: (detail){
        _tapDown(detail);
      },*/
      onDoubleTapDown: (detail) => _tapDown(detail),
      onTapUp: (detail) => print("onTapUp"),
      child: Stack(
        children: [
          Container(
            width: double.infinity,
            height: double.infinity,
            child: widget.child,
          ),
          ..._likeIcon,

        ],
      ),
    );
  }

  void _like() {
    print("点赞了呀，，，，，，，，，，，，，，");
    Widget like = _getLikeIcon();
    var pos = Positioned(
      child: like,
      left: globalOffset.dx - 50,
      top: globalOffset.dy - 150,
    );
    setState(() {
      _likeIcon.add(pos);
      print("setState 去改变ui");
    });
   /* Future.delayed(const Duration(seconds: 5), () {
      setState(() {
        _likeIcon.remove(pos);
        _cackeIcon.add(like);
      });
    });*/
  }

  Widget _getLikeIcon() {
    if (_cackeIcon.isNotEmpty)
      return _cackeIcon.removeAt(0);
    else
      return _buildLikeIcon();
  }

  Widget _buildLikeIcon() {
    return LikeAnimalIcon(mFinishListener: (widget){
      setState(() {
        _likeIcon.remove(widget);
        _cackeIcon.add(widget);
      });
    },);
  }

  void _tapDown(TapDownDetails detail) {
    setState(() {
      globalOffset = detail.globalPosition;
    });
  }
}

/*



* */
